'use strict';
exports = module.exports = function ($scope){
    async function test(){
        function aaa(){
            return new Promise((resolve, reject) => {
                setTimeout(() => {
                    resolve(111)
                },10e3)
            });
        }
        console.log('测试a执行')
        aaa().then(function(v){
            console.log('测试a', '成功返回', v)
        }, function(v){
            console.log('测试a', '失败返回', v)
        })
        ////////////////////////////////////////
        async function bbb(){
            return new Promise((resolve, reject) => {
                setTimeout(() => {
                    resolve(222)
                },4e3)
            });
        }
        console.log('测试b执行')
        var b = await bbb();
        console.log('测试b', b)
        ////////////////////////////////////////
        var pending = false;
        function ccc(){
            return new Promise((resolve, reject) => {
                pending = true;
                setTimeout(() => {
                    resolve(333)
                    pending = false;
                },4e3)
            });
        }
        console.log('测试c执行')
        ccc().then(function(v){
            console.log('测试c', '成功返回', v)
        }, function(v){
            console.log('测试c', '失败返回', v)
        })
        ////////////////////////////////////////
        async function ddd(){
            return new Promise((resolve, reject) => {
                setTimeout(() => {
                    function check(){
                        console.log('测试d.pending', pending)
                        if( pending ){
                            setTimeout(check,500);
                            return;
                        }
                        resolve(444)
                    }
                    check()
                },1e3)
            });
        }
        console.log('测试d执行')
        var d = await ddd();
        console.log('测试c', d)
        ////////////////////////////////////////
        function eee(){
            return new Promise((resolve, reject) => {
                Promise.resolve( new Promise((resolve, reject) => {
                    setTimeout(() => { resolve(555) },2e3)
                }))
            });
        }
        console.log('测试e执行')
        eee().then(function(v){
            console.log('测试e', '成功返回', v)
        }, function(v){
            console.log('测试e', '失败返回', v)
        })
        ////////////////////////////////////////
        function fff(){
            return new Promise((resolve, reject) => {
                new Promise((resolve, reject) => {
                    setTimeout(() => { resolve(666) },2e3)
                }).then(resolve, reject)
            });
        }
        console.log('测试f执行')
        fff().then(function(v){
            console.log('测试f', '成功返回', v)
        }, function(v){
            console.log('测试f', '失败返回', v)
        })
    }
    test()
}
